<div class="system-messages">
    <ul>
        <?php
        $messages = $this->messages;
        foreach ($messages as $message) :
            ?>
            <li><?= $message ?></li>
        <?php
        endforeach
        ?>
    </ul>
</div>
<div class="admin-search-n-filter">
    <div class="admin-hyperlink-btn">
        <a href="/classico/public/admin/order/index">Refresh</a>
    </div>
    <div class="admin-filter">
        <label>
            <select>
                <?php
                if (!isset($this->isProcess)) :
                    ?>
                    <option value="null">-- Is Process --</option>
                    <option value="1">True</option>
                    <option value="0">False</option>
                <?php
                endif;
                if ($this->isProcess === true) :
                    ?>
                    <option value="null">-- Is Process --</option>
                    <option value="1" selected="selected">True</option>
                    <option value="0">False</option>
                <?php
                endif;
                if ($this->isProcess === false) :
                    ?>
                    <option value="null">-- Is Process --</option>
                    <option value="1">True</option>
                    <option value="0" selected="selected">False</option>
                <?php
                endif;
                ?>
            </select>
        </label>
    </div>
</div>
<div class="datagrid">
    <table>
        <tr>
            <th width="2%"><label><input id="check-box-all" type="checkbox"/></label></th>
            <th width="2%">ID</th>
            <th>Name</th>
            <th width="11%">CreatedDate</th>
            <th width="5%">TotalCost</th>
            <th width="5%">Username</th>
            <th width="5%">Email</th>
            <th width="15%">RealName</th>
            <th width="5%">MobilePhone</th>
            <th width="5%" class="center">IsProcess</th>
            <th width="5%" class="center">Delete</th>
        </tr>
        <?php
        $orders = $this->orders;
        foreach ($orders as $index => $order) :
            ?>
            <tr class="<?= ($index % 2 == 0) ? 'alt' : '' ?>">
                <td>
                    <label>
                        <input class="check-box-order-id" type="checkbox" value="<?= $order['ID'] ?>"/>
                    </label>
                </td>
                <td><?= $order['ID'] ?></td>
                <td><?= $order['Name'] ?></td>
                <td><?= $order['CreatedDate'] ?></td>
                <td><?= $order['TotalCost'] ?></td>
                <td><?= $order['Username'] ?></td>
                <td><?= $order['Email'] ?></td>
                <td><?= $order['RealName'] ?></td>
                <td><?= $order['MobilePhone'] ?></td>
                <td class="center">
                    <?php
                    if (!$order['IsProcess']) :
                        ?>
                        <div class="enabled-block-icon tool-icon"></div>
                        <form action="/classico/public/admin/order/confirm" method="post">
                            <input type="hidden" name="isPost" value=""/>
                            <input type="hidden" name="orderID" value="<?= $order['ID'] ?>"/>
                        </form>
                    <?php
                    endif;
                    if ($order['IsProcess']) :
                        ?>
                        <div class="enabled-confirm-icon tool-icon"></div>
                        <form action="/classico/public/admin/order/unconfirm" method="post">
                            <input type="hidden" name="isPost" value=""/>
                            <input type="hidden" name="orderID" value="<?= $order['ID'] ?>"/>
                        </form>
                    <?php
                    endif
                    ?>
                </td>
                <td class="center">
                    <div class="enabled-delete-icon tool-icon"></div>
                    <form action="/classico/public/admin/order/delete" method="post">
                        <input type="hidden" name="isPost" value=""/>
                        <input type="hidden" name="orderIDs[]" value="<?= $order['ID'] ?>"/>
                    </form>
                </td>
            </tr>
        <?php
        endforeach
        ?>
    </table>
</div>
<?= $this->paginationControl($this->paginator, 'Sliding', 'my_pagination_control.phtml') ?>
<script type="text/javascript">
    $('#tool-btn-add, #tool-btn-update, #tool-btn-confirm')
        .removeClass('enabled-tool-btn');
    $('#tool-btn-unblock, #tool-btn-block')
        .removeClass('enabled-tool-btn');

    $('#tool-btn-add > div')
        .removeClass('enabled-add-icon')
        .addClass('disabled-add-icon');
    $('#tool-btn-update > div')
        .removeClass('enabled-update-icon')
        .addClass('disabled-update-icon');
    $('#tool-btn-confirm > div')
        .removeClass('enabled-confirm-icon')
        .addClass('disabled-confirm-icon');
    $('#tool-btn-unblock > div')
        .removeClass('enabled-unblock-icon')
        .addClass('disabled-unblock-icon');
    $('#tool-btn-block > div')
        .removeClass('enabled-block-icon')
        .addClass('disabled-block-icon');
</script>
<script type="text/javascript">
    $('.admin-filter select').change(function () {
        var currentURL = window.location.href;

        var forwardURL = currentURL.replace(/\/order\/[\w\W]*/, '');
        forwardURL = forwardURL.replace(/\/index\/[\w\W]*/, '');
        forwardURL = forwardURL.replace(/\/isProcess\/[\w\W]*/, '');
        forwardURL = forwardURL.replace(/\/page\/[\w\W]*/, '');

        forwardURL += '/order/index';

        var isProcessValue = $(this).val();
        if (isProcessValue != 'null') {
            forwardURL += '/isProcess/' + isProcessValue;
        }

        window.location.href = forwardURL;
    });
</script>
<script type="text/javascript">
    $('#check-box-all').click(function () {
        if ($(this).attr('checked')) {
            $('.check-box-order-id').attr('checked', true);
        } else {
            $('.check-box-order-id').attr('checked', false);
        }
    });

    $('.datagrid .tool-icon').click(function () {
        $(this).parent(null).find('form').submit();
    });
</script>
<script type="text/javascript">
    $('#tool-btn-delete.enabled-tool-btn').click(function () {
        var form = $(this).find('form');

        var checkedCheckBoxes = $('.check-box-order-id:checked');
        for (var i = 0; i < checkedCheckBoxes.length; i++) {
            var orderID = checkedCheckBoxes[i].value;
            var tag = '<input type="hidden" name="orderIDs[]" value="' + orderID + '"/>';
            form.append(tag);
        }

        form.submit();
    });
</script>